package xyz.ddlnt.servicemq.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import xyz.ddlnt.commonutil.constant.MqConstants;
import xyz.ddlnt.model.dto.FollowDTO;
import xyz.ddlnt.model.entity.UserInfo;
import xyz.ddlnt.servicemq.mapper.UserMapper;
import xyz.ddlnt.servicemq.service.UserService;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/9 19:44
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserInfo> implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public void postPlusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setIncrBy(UserInfo::getArticleCount, MqConstants.PLUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void postMinusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setDecrBy(UserInfo::getArticleCount, MqConstants.MINUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void followPlusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setIncrBy(UserInfo::getFollowingCount, MqConstants.PLUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void fansPlusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setIncrBy(UserInfo::getFollowerCount, MqConstants.PLUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void followMinusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setDecrBy(UserInfo::getFollowingCount, MqConstants.MINUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void fansMinusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setDecrBy(UserInfo::getFollowerCount, MqConstants.MINUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void collectedCountPlusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setIncrBy(UserInfo::getCollectedCount, MqConstants.PLUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }

    @Override
    public void collectedCountMinusOne(Long userId) {
        LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setDecrBy(UserInfo::getCollectedCount, MqConstants.MINUS_ONE)
                .eq(UserInfo::getId, userId);
        userMapper.update(updateWrapper);
    }
}
